package sg.edu.nus.iss.vmcs.builder;

import java.awt.BorderLayout;
import java.awt.Checkbox;
import java.awt.Font;
import java.awt.Frame;
import java.awt.GridLayout;
import java.awt.Label;
import java.awt.Panel;

import sg.edu.nus.iss.vmcs.machinery.DoorListener;
import sg.edu.nus.iss.vmcs.machinery.MachineryController;
import sg.edu.nus.iss.vmcs.machinery.MachinerySimulatorPanel;
import sg.edu.nus.iss.vmcs.machinery.StoreViewer;
import sg.edu.nus.iss.vmcs.store.Store;
import sg.edu.nus.iss.vmcs.store.StoreController;

/**
 * @version 1.0
 * @author Yeo Hee Ling
 */
public class MachineryUIBuilder extends UIBuilder {
	
	private MachineryController machineryController;
	private StoreController storeController;
	private MachinerySimulatorPanel machPanel;
	
	public MachineryUIBuilder(Frame frame, MachineryController machineryController) {
		this.machineryController = machineryController;
		this.storeController = machineryController.getMainController().getStoreController();
		machPanel = new MachinerySimulatorPanel(frame, machineryController);
	}
	
	public void buildVendingNorthPanel () {
		Label lb = new Label(machPanel.getTitle());
		lb.setFont(new Font("Helvetica", Font.BOLD, 24));
		lb.setAlignment(Label.CENTER);
		machPanel.add(BorderLayout.NORTH, lb);
	}
	
	public void buildVendingCenterPanel () {
		StoreViewer cashDisplay = new StoreViewer(Store.CASH, storeController);
		machPanel.setCashStoreDisplay(cashDisplay);
		
		StoreViewer drinksDisplay = new StoreViewer(Store.DRINK, storeController);
		machPanel.setDrinksStoreDisplay(drinksDisplay);

		Panel tp = new Panel();
		tp.setLayout(new GridLayout(0, 1));
		tp.add(cashDisplay);
		tp.add(drinksDisplay);
		machPanel.add(BorderLayout.CENTER, tp);
	}
	
	public void buildVendingSouthPanel () {
		Panel dp = new Panel();
		Checkbox doorDisplay = new Checkbox();
		doorDisplay.addItemListener(new DoorListener(machineryController));
		doorDisplay.setLabel("Door Locked");
		machPanel.setDoorDisplay(doorDisplay);
		dp.add(doorDisplay);
		
		machPanel.add(BorderLayout.SOUTH, dp);
		machPanel.pack();
	}
	
	public MachinerySimulatorPanel getResultPanel() {
		return this.machPanel;
	}
}
